//
//  ASTypeParser.h
//  FlashOutboard
//
//  Created by Martin Schiøth Dyrby on 1/30/11.
//  Copyright 2011 Molamil. All rights reserved.
//

#import <Cocoa/Cocoa.h>


@interface ASTypeParser : NSObject <NSXMLParserDelegate>
{
    NSMutableArray* items;
	NSMutableArray* children;
	NSMutableArray* methods;
	NSMutableArray* declared;
	NSMutableArray* inherited;
	NSString* path;
    NSString *keyInProgress;
    NSMutableString *textInProgress;
}

@property (retain) NSMutableArray *items;
@property (retain) NSMutableArray *children;
@property (retain) NSMutableArray *methods;
@property (retain) NSMutableArray *declared;
@property (retain) NSMutableArray *inherited;
@property (retain) NSString* path;

- (BOOL)parseData:(NSData *)d;
- (NSArray *)parseItems;

@end



/*
 
 
 package org.rabbitas.utils {
 import flash.utils.describeType;
 
 public class Type
 {
 private var _methods:Object;
 private var _readable:Object;
 private var _writable:Object;
 private var _isDynamic:Boolean = false;
 private var _name:String;
 private var _supers:XMLList;
 
 public function Type(obj:*)
 {
 _methods = new Object();
 _writable = new Object();
 _readable = new Object();
 
 var typeInfo:XML = describeType(obj);
 
 _isDynamic 	= (typeInfo.@isDynamic == "true");
 _name 		= typeInfo.@name;
 
 _supers 	= typeInfo.descendants("extendsClass");
 
 var accessors:XMLList = typeInfo.descendants("accessor");
 addAccessors(accessors);
 
 var variables:XMLList = typeInfo.descendants("variable");
 addVariables(variables);
 
 var methods:XMLList = typeInfo.descendants("method");
 addMethods(methods);
 }
 
 public function get writableProperties():Object
 {
 return _writable;
 }
 
 public function get readableProperties():Object
 {
 return _readable;
 }
 
 public function get methods():Object
 {
 return _methods;
 }
 
 public function get isDynamic():Boolean
 {
 return _isDynamic;
 }
 
 public function get name():String
 {
 return _name;
 }
 
 public function getMethodParamByName(name:String):Array
 {
 if(methods.hasOwnProperty("_" + name))
 {
 return methods["_" + name];
 }
 
 return null;			
 }
 
 public function getWriteableAccessorParamByName(name:String):String
 {
 if(writableProperties.hasOwnProperty(name))
 {
 return writableProperties[name];
 }
 
 return null;
 }
 
 public function getWritableProperties(packages:Array):Object {
 var properties:Object= new Object();
 var numPackages:int = packages.length;
 for(var s:String in writableProperties){
 for(var i:int = 0;i < numPackages; ++i) {
 var type:String = writableProperties[s];
 if(type.indexOf(packages[i]) == 0) {
 properties[s] = type;
 }
 }
 }
 
 return properties;
 }
 
 public function matchesClass(typeName:String) : Boolean {
 return (typeName == name) || (_supers.(@type==typeName).length() > 0);
 }
 
 ///////////////////////////////////////
 /////////////// PRIVATE ///////////////
 ///////////////////////////////////////
 
 private function addAccessors(accessors:XMLList):void
 {
 var numAccessors:int = accessors.length();
 
 for(var i:int = 0; i < numAccessors; i++)
 {
 var accessor:XML = accessors[i];
 
 var name:String = accessor.@name;
 var access:String = accessor.@access;
 var type:String = accessor.@type;
 
 switch(access)
 {
 case 'readonly':
 _readable[name] = type;
 break;
 case 'writeonly':
 _writable[name] = type;
 break;
 case 'readwrite':
 _readable[name] = type;
 _writable[name] = type;
 break;
 }
 }
 }
 
 private function addVariables(variables:XMLList):void
 {
 var numVariables:int = variables.length();
 
 for(var i:int = 0; i < numVariables; i++)
 {
 var variable:XML = variables[i];
 
 var name:String = variable.@name;
 var type:String = variable.@type;
 
 _readable[name] = type;
 _writable[name] = type;
 }
 }
 
 private function addMethods(methods:XMLList):void
 {
 var numMethods:int = methods.length();
 
 for(var i:int = 0; i < numMethods; i++)
 {
 var method:XML = methods[i];
 var params:XMLList = method.children();
 var paramList:Array = [];
 var name:String = "_"+method.@name;
 
 var numParams:int = params.length();
 for(var j:int = 0; j < numParams; j++)
 {
 var param:XML = params[j];
 var type:String = param.@type;
 
 paramList.push(type);
 }
 
 try
 {
 _methods[name] = paramList;
 }
 catch(e:ReferenceError)
 {
 trace(e.message);
 }
 }
 }
 
 }
 }
 
 */
